import { BaseResponse } from '@/type/api'
import instance from './index'

/**
 * 登陆
 */
export const login = (data = {}): Promise<BaseResponse> => {
  return instance.request({ url: '/api/v1/user/login', data: data, method: 'POST' })
}

/**
 * 根据token获取用户信息
 */
export const getInfo = (data = {}): Promise<BaseResponse> => {
  return instance.request({ url: '/api/v1/user/token', params: data, method: 'GET' })
}

/**
 * 检测账号字段是否注册
 */
export const checkAccount = (data = {}): Promise<BaseResponse> => {
  return instance.request({ url: '/api/v1/user/check', params: data, method: 'GET' })
}

/**
 * 注册
 */
export const register = (data = {}): Promise<BaseResponse> => {
  return instance.request({ url: '/api/v1/user/register', data: data, method: 'POST' })
}

/**
 * 编辑信息
 */
export const edit = (data = {}, id: number): Promise<BaseResponse> => {
  return instance.request({ url: '/api/v1/user/edit/' + id, data: data, method: 'PUT' })
}

/**
 * 上传头像
 */
export const upload = (data = {}, id: number): Promise<BaseResponse> => {
  return instance.request({ headers: { 'Content-Type': 'multipart/form-data' }, url: '/api/v1/user/upload/' + id, data, method: 'POST' })
}

/**
 * 获取消息
 */
export const message = (data = {}, id: number): Promise<BaseResponse> => {
  return instance.request({ url: '/api/v1/message/' + id, params: data, method: 'get' })
}

/**
 * 获取验证码
 */
export const getVerification = (data = {}): Promise<Blob> => {
  const config = { url: '/java/api/v1/captcha', params: data, method: 'get', port: 9002 }
  return instance.request(config)
}

/**
 * 验证 验证码
 */
export const verification = (data = {}): Promise<BaseResponse> => {
  const config = { url: '/java/api/v1/verification', params: data, method: 'get', port: 9002 }
  return instance.request(config)
}
